package blackberry.util;

import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.Ui;


/**
 * @deprecated Font로 대체
 */
public class DjFontData {

	public static final int DEFAULT = -1;

	private static final int DEFAULT_STYLE = Font.PLAIN;
	private static final int DEFAULT_HEIGHT = Font.getDefault().getHeight();
	private static final int DEFAULT_UNITS = Ui.UNITS_px;
	
	private final int style;
	private final int height;
	private final int units;

	public DjFontData(int style, int height, int units) {
		if (style == DEFAULT)
			this.style = DEFAULT_STYLE;
		else 
			this.style = style;
				
		if (height == DEFAULT)
			this.height = DEFAULT_HEIGHT;
		else 
			this.height = checkHeight(height);
		
		if (units == DEFAULT)
			this.units = DEFAULT_UNITS;
		else
			this.units = checkUnits(units);
	}
	
	private int checkHeight(int height){
		return (height <= 0) ? DEFAULT_HEIGHT : height;
	}

	private int checkUnits(int units){
		return (units != Ui.UNITS_cm 
				&& units != Ui.UNITS_cpt
				&& units != Ui.UNITS_m
				&& units != Ui.UNITS_mm
				&& units != Ui.UNITS_pm
				&& units != Ui.UNITS_pt
				&& units != Ui.UNITS_px
				&& units != Ui.UNITS_µm) ? DEFAULT_UNITS : units;
	}
	
	public int getStyle() {
		return style;
	}

	public int getHeight() {
		return height;
	}

	public int getUnists() {
		return units;
	}

	public void setFont(Field field){
		field.setFont(Font.getDefault().derive(style, height, units));
	}
}